package com.yanqu.road.server.cmd.wingroom;

import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.wingroom.WingRoomModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

/**
 * @author ：zfr
 * @date ：2022/2/8 15:11
 */
@Cmd(code = GameProtocol.S_WING_ROOM_UNLOCK_REGION, desc = "解锁区域")
public class UnlockRegionCmd extends AbstractCommand {
    private int regionId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WingRoomProto.UnlockRegionReqMsg reqMsg = WingRoomProto.UnlockRegionReqMsg.parseFrom(packet.getBytes());
        regionId = reqMsg.getRegionId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(WingRoomModule.class).unlockRegion(regionId);
    }

    @Override
    public void sendData(GamePlayer player) {
        WingRoomProto.UnlockRegionRespMsg.Builder respMsg = WingRoomProto.UnlockRegionRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(Protocol.U_WING_ROOM_UNLOCK_REGION, respMsg);
    }
}
